### Prepare
Here is the prepare steps to configure mail server in Ajenti + RainLoop :
1. Make sure you already create new website in sub domain for rainloop, example: mail.yourdomain.com
2. Click manage on it, then on content tab, create PHP FastCGI >> Click Apply Changes
3. On advanced tab, at custom configuration paste this code  
```
location ^~ /data {
  deny all;
}
```
then click Apply Changes  
4. Done

### Install IMAP + POP3 mail server  
1. Install Ajenti IMAP + POP3 mail server
```
apt-get install ajenti-v-mail -y
apt-get install courier-pop -y
```
2. Don't forget to allow firewall for imap, pop3 and smtp port 25, 143, 465, 587, 993, 2525, 2526
3. Go to menu Mail then you will find DKIM, DMARC, and SPF configuration, if there is empty, you have to generate new.
4. Put the DKIM, DMARC and SPF on the DNS to avoid blacklist to your IP
5. Done

### Install RainLoop
This step is require Terminal or SSH Putty :
1. Go inside folder rainloop, example: srv/mail.yourdomain.com  
```
cd /srv/mail.yourdomain.com
```
2. Install requirement library (note: we use php 7.2)  
```
apt-get install php7.2-cli php7.2-curl
```
3. Download and Install script rainloop  
```
wget -qO- http://repository.rainloop.net/installer.php | php
find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;
chown -R www-data:www-data .
```
4. Done

### IMAP and SMTP Information
```
Username: user@example.com
Password: your_mailbox_password
IMAP Server: panel.example.com
IMAP Port: 143
IMAP Encryption: STARTTLS (Accept all certificates)
SMTP Server: panel.example.com
SMTP Port: 25
SMTP Encryption: None
```

### Configure RainLoop
1. Go to http://mail.yourdomain.com/?admin
2. Default login is admin:12345
3. Go to domain tab
4. Click Add new Domain
5. Fill the IMAP and SMTP information
6. Done, now you can logout and then login with your own email